package com.ceshiren.hogwarts.restassured.wechat.task;

import com.ceshiren.hogwarts.restassured.wechat.apiobject.DepartmentObject;
import com.ceshiren.hogwarts.restassured.wechat.apiobject.MembersObject;
import io.restassured.response.Response;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author Seven
 * @date 2020/12/23 15:15
 */
public class EvnHelperTask {
    public static void clearDepartment(String accessToken){
        Response response = DepartmentObject.listDepartment(accessToken,1);
        List<Integer> departmentIds = new ArrayList<>();
        departmentIds = response.path("department.id");
        for(int departmentId : departmentIds){
            if(1==departmentId){
                continue;
            }
            DepartmentObject.delDepartment(accessToken,departmentId);
        }
    }

    public static void clearMembers(String accessToken,String departmentId){
        Response response = MembersObject.listMembers(accessToken,departmentId);
        List<String> userIdList = response.path("userlist.userid");
        List<String> uList = new ArrayList<>();
        for (String uid : userIdList){
            if("xiaoxiao".equals(uid)){
                continue;
            }
            uList.add(uid);
        }
        HashMap<String,List<String>> uIds = new HashMap<>();
        uIds.put("useridlist",uList);
        MembersObject.delMembers(accessToken,uIds);
    }
}
